package com.wk.jetpackdemo.remote

import com.google.gson.GsonBuilder
import com.wk.jetpackdemo.remote.api.PaoService
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

object HttpUtils {

    private val okHttpClient: OkHttpClient by lazy {
        val httpLoggingInterceptor = HttpLoggingInterceptor()
        httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
        OkHttpClient.Builder()
                .addInterceptor(httpLoggingInterceptor)
                .build()
    }

    val paoService: PaoService by lazy {
        val gson = GsonBuilder().create()
        Retrofit.Builder().baseUrl(Constants.HOST_API).client(okHttpClient)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build().create(PaoService::class.java)
    }

}